<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh">
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
%>
<head>
    <meta charset="utf-8" />
    <title>保险代理后台管理系统</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
    <jsp:include page="../common/header.jsp"></jsp:include>
    <%@include file="../common/taglib.jsp"%>
    
    <!-- ================== 单独作用于本页表格td ================== -->
    <style>
        .input-group{
            width: 270px;
        }
         .dropdown-menu {
             position: absolute;
             top: 100%;
             left: 0;
             z-index: 1000;
             display: none;
             float: left;
             min-width: 160px;
             padding: 5px 0;
             margin: 2px 0 0;
             font-size: 14px;
             text-align: left;
             list-style: none;
             background-color: #fff;
             -webkit-background-clip: padding-box;
             background-clip: padding-box;
             border: 1px solid #ccc;
             border: 1px solid rgba(0,0,0,.15);
             border-radius: 4px;
         }

    </style>
    <!-- ================== 单独作用于本页表格td ================== -->

</head>
<body>
<!-- begin #page-loader -->
<div id="page-loader" class="fade in"><span class="spinner"></span></div>
<!-- end #page-loader -->

<!-- begin #page-container -->
<div id="page-container" class="fade page-sidebar-fixed page-header-fixed">
    <jsp:include page="../common/top.jsp"/>

    <!-- begin #sidebar -->
    <jsp:include page="../common/sitebar.jsp"/>
    <div class="sidebar-bg"></div>
    <!-- end #sidebar -->
<!-- begin #content -->
<div id="content" class="content">
	<!-- begin page-header -->
	<!-- end page-header -->
	
	<!-- begin row -->
	<div class="row">
	    <!-- begin col-12 -->
	    <div class="col-md-12">
	        <!-- begin panel -->
            <ul class="nav nav-tabs" id="havePay">
                <shiro:hasPermission name='order:havePay:company'>
                    <li class="active"><a href="#default-tab-1" data-toggle="tab" onclick="changeUrl(1)">保险公司</a></li>
                </shiro:hasPermission>
                <shiro:hasPermission name='order:havePay:channel'>
                    <li class=""><a href="#default-tab-2" data-toggle="tab" onclick="changeUrl(2)">渠道</a></li>
                </shiro:hasPermission>
                    <li class="hidden" id="detail"><a href="javascript:void(0);">保单详情</a></li>
                <shiro:hasPermission name='order:havePay:company:downLoad'>
                <li class="link-down">
                    <span onclick="openModel(1)" id="down">
                        <i class="fa fa-download fa-2"></i>下载列表
                    </span>
                </li>
                </shiro:hasPermission>
                <shiro:hasPermission name='order:havePay:channel:downLoad'>
                <li class="link-down hidden">
                    <span onclick="openModel(2)" id="down1">
                        <i class="fa fa-download fa-2"></i>下载列表
                    </span>
                </li>
                </shiro:hasPermission>
            </ul>
            <div class="tab-content">
                <div class="tab-pane fade active in" id="default-tab-1">
                    <form class="form-horizontal">
                        <div class="form-group">
                            <label class="col-md-1 control-label" style="width: 110px;">保险公司：</label>
                            <div class="col-md-2">
                                <select id="insyrerId" name="insyrerId" class="form-control">
                                    <option value="0">请选择</option>
                                    <c:forEach items="${insurerList}" var="isl">
                                        <option value="${isl.tid}">${isl.name}</option>
                                    </c:forEach>
                                </select>
                            </div>

                            <label class="col-md-1 control-label">保单号：</label>
                            <div class="col-md-2">
                                <input type="text" id="ordNum" name="ordNum"  class="form-control" placeholder="保单号" />
                            </div>
                            <label class="col-md-1 control-label">车牌号：</label>
                            <div class="col-md-2">
                                <input type="text" name="plateNum" id="plateNum"  class="form-control" placeholder="车牌号" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-1 control-label" style="width: 110px;">渠道：</label>
                            <div id="cscs" class="col-md-2">
                                <input type="text" id="channel" name="channel" data-toggle="dropdown"  class="form-control dropdown-toggle" placeholder="渠道" />
                                <%--<input type="hidden" name="channelId" id="channelId">--%>
                                <%--<ul class="hidden" id="ch" style="border: 1px solid gainsboro"></ul>
                               --%>
                                <ul id="ch" class="dropdown-menu hidden" style="max-height: 200px;overflow: auto;margin-left: 15px;">
                                    <%--<li><a href="#">Action</a></li><li><a href="#">Action</a></li>--%>
                                </ul>
                            </div>
                            <label class="col-md-1 control-label">结算日期:</label>
                            <div class="col-md-3">
                                <div class="input-group input-daterange">
                                    <input type="text" class="form-control datepicker-default" name="insureStartDate" id="insureStartDate" placeholder="开始日期" />
                                    <span class="input-group-addon">至</span>
                                    <input type="text" class="form-control datepicker-default" name="insureEndDate" id="insureEndDate" placeholder="结束日期"/>
                                </div>
                            </div>
                            <div class="col-md-3">
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                <button type="button" onclick="search()" class="btn btn-primary m-r-5 m-b-5">查询</button>
                                <%--&nbsp;&nbsp;&nbsp;&nbsp;
                                <button type="button" onclick="openModel(1)" class="btn btn-primary m-r-5 m-b-5">下载</button>--%>
                            </div>
                        </div>
                    </form>
                      <div class="table-responsive" >
                          <table id="modeltable" style="word-break:break-all;word-wrap:break-word" class="table table-striped table-bordered">
                              <thead>
                                  <tr>
                                      <th width="6%">保单号</th>
                                      <th width="6%">付款主体</th>
                                      <th width="6%">保险公司</th>
                                      <th width="6%">渠道</th>
                                      <th width="6%">渠道联系电话</th>
                                      <th width="6%">险种</th>
                                      <th width="6%">被保险人</th>
                                      <th width="6%">被保险人证件号</th>
                                      <th width="6%">车牌号</th>
                                      <th width="6%">车主姓名</th>
                                      <th width="6%">商业保险费(元)</th>
                                      <th width="6%">交强保险费(元)</th>
                                      <th width="6%">车船税(元)</th>
                                      <th width="6%">全保费(元)</th>
                                      <th width="6%">保险公司返佣费(元)</th>
                                      <th width="6%">开单日期</th>
                                      <th width="6%">起保日期</th>
                                      <th width="6%">保险公司结算日期</th>
                                      <th width="6%">核对是否一致</th>
                                      <th width="6%">实收保险公司返点费(元)</th>
                                      <th width="6%">操作</th>
                                  </tr>
                              </thead>
                          </table>
                      </div>
                </div>
                <div class="tab-pane fade" id="default-tab-2">
                    <form class="form-horizontal">
                        <div class="form-group">
                            <label class="col-md-1 control-label" style="width: 110px;">保险公司：</label>
                            <div class="col-md-2">
                                <select id="insyrerId1" name="insyrerId" class="form-control">
                                    <option value="0">请选择</option>
                                    <c:forEach items="${insurerList}" var="isl">
                                        <option value="${isl.tid}">${isl.name}</option>
                                    </c:forEach>
                                </select>
                            </div>

                            <label class="col-md-1 control-label">保单号：</label>
                            <div class="col-md-2">
                                <input type="text" id="ordNum1" name="ordNum"  class="form-control" placeholder="保单号" />
                            </div>
                            <label class="col-md-1 control-label">车牌号：</label>
                            <div class="col-md-2">
                                <input type="text" name="plateNum" id="plateNum1"  class="form-control" placeholder="车牌号" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-1 control-label" style="width: 110px;">渠道：</label>
                            <div class="col-md-2">
                                <input type="hidden" name="channelId" id="channelId">
                                <input type="text" id="channels" name="channel" data-toggle="dropdown"  class="form-control dropdown-toggle" placeholder="渠道" />
                                <ul id="chs" class="dropdown-menu" style="max-height: 200px;overflow: auto;margin-left: 15px;">
                                </ul>
                            </div>
                            <label class="col-md-1 control-label">结算日期：</label>
                            <div class="col-md-3">
                                <div class="input-group input-daterange">
                                    <input type="text" class="form-control datepicker-default" name="insureStartDate" id="insureStartDate1" placeholder="开始日期" />
                                    <span class="input-group-addon">至</span>
                                    <input type="text" class="form-control datepicker-default" name="insureEndDate" id="insureEndDate1" placeholder="结束日期"/>
                                </div>
                            </div>
                            <div class="col-md-3">
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                <button type="button" onclick="search1()" class="btn btn-primary m-r-5 m-b-5">查询</button>
                                <%--&nbsp;&nbsp;&nbsp;&nbsp;
                                <button type="button" onclick="openModel(2)" class="btn btn-primary m-r-5 m-b-5">下载</button>--%>
                            </div>
                        </div>
                    </form>
                    <div class="table-responsive" >
                        <table id="modeltable1" style="word-break:break-all;word-wrap:break-word" class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th width="6%">保单号</th>
                                <th width="6%">付款主体</th>
                                <th width="6%">保险公司</th>
                                <th width="6%">渠道</th>
                                <th width="6%">渠道联系电话</th>
                                <th width="6%">险种</th>
                                <th width="6%">被保险人</th>
                                <th width="6%">被保险人证件号</th>
                                <th width="6%">车牌号</th>
                                <th width="6%">商业保险费(元)</th>
                                <th width="6%">交强保险费(元)</th>
                                <th width="6%">车船税(元)</th>
                                <th width="6%">全保费(元)</th>
                                <th width="6%">开单日期</th>
                                <th width="6%">起保日期</th>
                                <th width="6%">渠道返点(%)</th>
                                <th width="6%">渠道返佣费(元)</th>
                                <th width="6%">渠道结算日期</th>
                                <th width="6%">应收保费(元)</th>
                                <th width="6%">账期到期日</th>
                            </tr>
                            </thead>
                        </table>
                    </div>
                </div>
                <div id="default-tab-3" class="tab-pane fade ">
                    <div id="iframeParent">
                        <iframe width="100%" height="100%" scrolling="no" frameborder="0" id="iframe"></iframe>
                    </div>
                </div>
                <!-- #modal-alert -->
                <%--提示框--%>
                <div class="modal fade" id="modal-dialog"  tabindex="-1" role="dialog" style="z-index: 999999">
                    <input type="hidden" name="type" id="typee">
                    <div class="modal-dialog modal-sm">

                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title">温馨提示</h4>
                            </div>
                            <div class="modal-body" id="me">
                            </div>
                            <div class="modal-footer">
                                <a href="javascript:;" onclick="doSomeThing()" class="btn btn-sm btn-primary">确定</a>
                                <a href="javascript:;" class="btn btn-sm btn-default" onclick="closeModelss()">取消</a>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 应收订单退保弹出框begin -->
                <div class="modal fade" id="modalSurrender" >
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" onclick="closeModels()" aria-hidden="true">×</button>
                                <h5 class="modal-title">退保</h5>
                            </div>
                            <div class="modal-body">
                                <form class="form-horizontal" id="myForm" onsubmit="return false" data-parsley-validate="true">
                                    <input type="hidden" id="surrenderTid" name="tid">
                                    <input type="hidden" id="orderTid" name="ordId">
                                    <input type="hidden" id="channelFlag" name="channelFlag">
                                <section class="form-horizontal">
                                    <div class="form-group">
                                        <label class="col-md-5 control-label">退保保险公司扣除手续费:</label>
                                        <div class="col-md-6">
                                            <div class="input-group">
                                                <input type="text" class="form-control" id="inputPayInsurerAmt" name="payInsurerAmt" data-parsley-money="true" data-parsley-money-message="请输入正确的数字格式" data-parsley-required="true" data-parsley-required-message="请输入退保保险公司扣除手续费">
                                                <%-- data-parsley-money-message="请输入9位以内的整数或小数且小数点后只有两位"--%>
                                                <span class="input-group-addon">元</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-5 control-label">退保应扣除渠道佣金:</label>
                                        <div class="col-md-6">
                                            <div class="input-group">
                                                <input type="text" class="form-control" id="inputMustPremiumAmt" name="mustPremiumAmt" data-parsley-money="true" data-parsley-money-message="请输入正确的数字格式" data-parsley-required="true" data-parsley-required-message="请输入退保应扣除渠道佣金">
                                                <span class="input-group-addon">元</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group hidden" id="mustPremium">
                                        <label class="col-md-5 control-label">退保渠道应还保费:</label>
                                        <div class="col-md-6">
                                            <div class="input-group">
                                                <input type="hidden" class="form-control" id="inputMustPremium" name="mustPremium" data-parsley-money="true" data-parsley-money-message="请输入正确的数字格式" data-parsley-required="true" data-parsley-required-message="请输入退保渠道应还保费">
                                                <span class="input-group-addon">元</span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-5">起保日期:</label>
                                        <div class="col-md-6">
                                            <p class="form-control-static" id="inputInsuranceDate"></p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-5">退保日期:</label>
                                        <div class="col-md-6">
                                            <input type="text" class="form-control datepicker-default" id="inputSurrenderDate" name="surrenderDateStr" data-parsley-required="true" data-parsley-required-message="请输入退保日期"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-5 control-label">备注:</label>
                                        <div class="col-md-6">
                                            <textarea class="form-control" id="surrenderRemark" name="remark" placeholder="如有需要，请填写100字符以内的备注！" rows="5" data-parsley-length="[1, 100]"  data-parsley-length-message="请输入100字符以内" data-parsley-required="true" data-parsley-required-message="请输入退保备注"></textarea>
                                        </div>
                                    </div>
                                </section>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <a onclick="orderSurrender();" class="btn btn-sm btn-primary">提交</a>
                                <%--<button type="submit" class="btn btn-sm btn-danger">提交</button>--%>
                                <a href="javascript:;" onclick="closeModel()" class="btn btn-sm btn-default">取消</a>
                            </div>
                        </div>
                    </div>
                </div>
                </div>

            </div>      <!-- end panel -->
        </div>
              <!-- end col-12 -->
    </div>
          <!-- end row -->
</div>
<!-- end #content -->

<!-- end page container -->
<jsp:include page="../common/footer.jsp"/>
<script src="/static/js/order/order.js"></script>
<script>
    $(document).ready(function() {

        App.init();
        TableManageFixedHeader.init();
        wrapTable1();
        wrapTable2();

        $('.selectpicker').selectpicker({
            style: 'btn-white',
            size: 5
        });
        //日期控件
        $(".datepicker-default").datepicker({
            autoclose: true, //自动关闭
            beforeShowDay: $.noop,    //在显示日期之前调用的函数
            calendarWeeks: false,     //是否显示今年是第几周
            clearBtn: false,          //显示清除按钮
            daysOfWeekDisabled: [],   //星期几不可选
            endDate: Infinity,        //日历结束日期
            forceParse: true,         //是否强制转换不符合格式的字符串
            format: 'yyyy-mm-dd',     //日期格式
            keyboardNavigation: true, //是否显示箭头导航
            language: "zh-CN",           //语言
            minViewMode: 0,
            orientation: "auto",      //方向
            rtl: false,
            startDate: -Infinity,     //日历开始日期
            startView: 0,             //开始显示
            todayBtn: false,          //今天按钮
            todayHighlight: true,    //今天高亮
            weekStart: 0
        });


        //业务员赋值
        $("#email").click(function () {
            var value = $("#email :selected").val();
            if(value!="请选择"){
                $('#userName').val($('#email :selected').text());
            }
        });

        //保险公司赋值
        $("#select").click(function () {
            var value = $('#select :selected').val();
            if(value!="请选择"){
                $('#company').val($('#select :selected').text());
            }
        })

        //查询所有渠道名称
        $("#channel").keyup(function () {
            var name = $("#channel").val();
            $("#ch").addClass("hidden");
            if(name!=null&&name!=""){
                $("#ch").html("");
                $("#channelId").val("");
                $.ajax({
                    url:"/channel/findAllChannelName/"+name,
                    data:{},
                    type:"get",
                    success:function (data) {
                        if(data.success){
                            $("#ch").removeClass("hidden");
                            var channelIds = "";
                            var chHtml = "";
                            for (var i in data.result){
                                console.log("companyRegisterName--------"+data.result[i].companyRegisterName);

                                if(data.result[i].companyRegisterName!=null){
                                    chHtml += '<li value='+data.result[i].tid+'><a href="javascript:;">'+data.result[i].companyRegisterName+'</a></li>';
                                }else{
                                    chHtml += '<li value='+data.result[i].tid+'><a href="javascript:;">'+data.result[i].contact.name+'</a></li>';
                                }
                                channelIds += "," + data.result[i].tid;
                            }
                            /*var width = parseInt($("#channel").width());*/
                            if(channelIds!=null&&channelIds!=""){
                                channelIds = channelIds.substring(1,channelIds.length);
                                $("#ch").parent().addClass("open");
                            }else{
                                channelIds = -1;
                                $("#ch").parent().removeClass("open");
                            }
                            $("#ch").html(chHtml);

                            $("#channelId").val(channelIds);
                            $("#ch li").click(function () {
                                $("#channel").val($(this).text());
                                $("#channelId").val($(this).val());
                                $("#ch").parent().removeClass("open");
                            })

                        }else{
                            $("#channelId").val(-1);
                            $("#ch").parent().removeClass("open");
                        }
                    },
                    dataType:"json"
                })
            }else{
                $("#ch").parent().removeClass("open");
                $("#channelId").val("");
                $("#ch li").remove();
            }
        })

        $("#channels").keyup(function () {
            var name = $("#channels").val();
            $("#chs").addClass("hidden");
            if(name!=null&&name!=""){
                $("#chs").html("");
                $("#channelId").val("");
                $.ajax({
                    url:"/channel/findAllChannelName/"+name,
                    data:{},
                    type:"get",
                    success:function (data) {
                        if(data.success){
                            $("#chs").removeClass("hidden");
                            var channelIds = "";
                            var chHtml = "";
                            for (var i in data.result){
                                console.log("companyRegisterName--------"+data.result[i].companyRegisterName);

                                if(data.result[i].companyRegisterName!=null){
                                    chHtml += '<li value='+data.result[i].tid+'><a href="javascript:;">'+data.result[i].companyRegisterName+'</a></li>';
                                }else{
                                    chHtml += '<li value='+data.result[i].tid+'><a href="javascript:;">'+data.result[i].contact.name+'</a></li>';
                                }
                                channelIds += "," + data.result[i].tid;
                            }
                            /*var width = parseInt($("#channel").width());*/
                            if(channelIds!=null&&channelIds!=""){
                                channelIds = channelIds.substring(1,channelIds.length);
                                $("#chs").parent().addClass("open");
                            }else{
                                channelIds = -1;
                                $("#chs").parent().removeClass("open");
                            }
                            $("#chs").html(chHtml);

                            $("#channelId").val(channelIds);
                            $("#chs li").click(function () {
                                $("#channels").val($(this).text());
                                $("#channelId").val($(this).val());
                                $("#chs").parent().removeClass("open");
                            })

                        }else{
                            $("#channelId").val(-1);
                            $("#chs").parent().removeClass("open");
                        }
                    },
                    dataType:"json"
                })
            }else{
                $("#chs").parent().removeClass("open");
                $("#channelId").val("");
                $("#chs li").remove();
            }
        })


    });


    //分页展示
    var table1;
    var table2;
    function wrapTable1() {
        table1 = $("#modeltable").DataTable({
            "bAutoWidth": false,
            /*"order": [[0, 'desc']],*/
            ordering:false,
            "pagingType": "simple_numbers",//设置分页控件的模式
            searching: false,//屏蔽datatales的查询框
            aLengthMenu: [15],//设置一页展示10条记录
            "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
            "oLanguage": {  //对表格国际化
                "sLengthMenu": "每页显示 _MENU_条",
                "sZeroRecords": "无匹配结果，请更换筛选条件再试",
                "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
                "sInfoEmpty": "当前第 0 - 0 条　共计 0 条",
                "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
                "sSearch": "搜索：",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                }
            },
            "processing": true, //打开数据加载时的等待效果
            "serverSide": true,//打开后台分页
            "ajax": {
                "url": "/ins/order/getInsyrerData",
                "dataSrc": "aaData",
                "data": function (params) {
                    var insyrerId  =$('#insyrerId :selected').val();
                    if(insyrerId==0){
                        params.insyrerId =null;
                    }else{
                        params.insyrerId = insyrerId;
                    }
                    params.channelIds =  $('#channelId').val();
                    params.ordNum = $('#ordNum').val();
                    params.plateNum = $('#plateNum').val();
                    /*if (channelId==0){
                        params.channelId =null;
                    }else{
                        params.channelId =channelId;
                    }*/
                    params.insureStartDate = $('#insureStartDate').val();
                    params.insureEndDate = $('#insureEndDate').val();
                }
            },
            "columns": [
                {
                    "bSortable": false,
                    "defaultContent": '--',
                    "render": function (data, type, row, meta) {
                        var tids = row.ordNum;
                        return "<a href='javascript:void(0);' onclick='showOrderInfo("+row.tid+")'>"+tids+"</a>";
                    }
                },
                {
                    "bSortable": false,
                    "defaultContent": '--',
                    "render": function (data, type, row, meta) {
                        var paySubject = row.paySubject;
                        if(paySubject==1){
                            return "环宇康泰";
                        }else if(paySubject==2){
                            return "青岛盛达";
                        }else if(paySubject==3){
                            return "玉环天云";
                        }else {
                            return "汉龙";
                        }
                    }
                },
                {
                    "data": "insyrerName",
                    "defaultContent": '--',
                    "bSortable": false
                },
                {
                    "data": "channel.companyRegisterName",
                    "defaultContent": '--',
                    "bSortable": false,
                    "render":function (data, type, row, meta) {
                        if(row.channel.companyRegisterName==null){
                            return row.channel.contact.name;
                        }else{
                            return row.channel.companyRegisterName;
                        }
                    }
                },
                {
                    "data": "channel.contact.telephone",
                    "defaultContent": '--',
                    "bSortable": false
                },
                {
                    "bSortable": false,
                    "defaultContent": '--',
                    "render": function (data, type, row, meta) {
                        var typeInsurance = row.typeInsurance;
                        if(typeInsurance==0){
                            return "交强险";
                        }else if(typeInsurance==1){
                            return "商业险";
                        }
                    }
                },
                {
                    "data": "insurant",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "orgIdCode",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "plateNum",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "carOwner",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "mercialPremium",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "pulsoryPremium",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "vechcleVesselTax",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "allPremium",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "mustRebateAmt",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "dateIssuance",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "datePolicy" +
                    "",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "receiptDate",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "bSortable": false,
                    "defaultContent": '--',
                    "render": function (data, type, row, meta) {
                        var checkResult = row.checkResult;
                        if(checkResult==1){
                            return "一致";
                        }else if(checkResult==2){
                            return "不一致";
                        }
                    }
                },
                {
                    "data": "realRebateAmt",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
            ],

            "columnDefs": [{
                "targets": 20,//是操作按钮目标列
                "data": null,
                "render": function (data, type, row) {
                    var status = row.status;
                    if(status==1){
                        var ordId = row.tid+","+row.capitalId;
                        console.log("ordid------------------"+ordId)
                        var capitalId = "'"+row.capitalId+"'";
                        // return '<a href="javascript:void(0);" onclick="openModels(\''+ids+'\')">'+ids+'</a>';
                        return "<shiro:hasPermission name='order:havePay:company:surrender'>"+
                            "<a href='javascript:void(0);' onclick='openModels("+ordId+")'>退保</a>"+
                            "</shiro:hasPermission>";
                    }else{
                        return null;
                    }
                }
            }]
        });

    }

    function wrapTable2() {
        table2 = $("#modeltable1").DataTable({
            "bAutoWidth": false,
            /*"order": [[0, 'desc']],*/
            ordering:false,
            "pagingType": "simple_numbers",//设置分页控件的模式
            searching: false,//屏蔽datatales的查询框
            aLengthMenu: [15],//设置一页展示10条记录
            "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
            "oLanguage": {  //对表格国际化
                "sLengthMenu": "每页显示 _MENU_条",
                "sZeroRecords": "无匹配结果，请更换筛选条件再试",
                "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
                "sInfoEmpty": "当前第 0 - 0 条　共计 0 条",
                "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
                "sSearch": "搜索：",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                }
            },
            "processing": true, //打开数据加载时的等待效果
            "serverSide": true,//打开后台分页
            "ajax": {
                "url": "/ins/order/getChannelData",
                "dataSrc": "aaData",
                "data": function (params) {
                    var insyrerId  =$('#insyrerId1 :selected').val();
                    if(insyrerId==0){
                        params.insyrerId =null;
                    }else{
                        params.insyrerId = insyrerId;
                    }
                    params.channelIds =  $('#channelId').val();

                    params.ordNum = $('#ordNum1').val();
                    params.plateNum = $('#plateNum1').val();
                    params.insureStartDate = $('#insureStartDate1').val();
                    params.insureEndDate = $('#insureEndDate1').val();
                }
            },
            "columns": [
                {
                    "bSortable": false,
                    "defaultContent": '--',
                    "render": function (data, type, row, meta) {
                        var tids = row.ordNum;
                        return "<a href='javascript:void(0);' onclick='showOrderInfo("+row.tid+")'>"+tids+"</a>";
                    }
                },
                {
                    "bSortable": false,
                    "defaultContent": '--',
                    "render": function (data, type, row, meta) {
                        var paySubject = row.paySubject;
                        if(paySubject==1){
                            return "环宇康泰";
                        }else if(paySubject==2){
                            return "青岛盛达";
                        }else if(paySubject==3){
                            return "玉环天云";
                        }else {
                            return "汉龙";
                        }
                    }

                },
                {
                    "data": "insyrerName",
                    "defaultContent": '--',
                    "bSortable": false
                },
                {
                    "bSortable": false,
                    "defaultContent": '--',
                    "render": function (data, type, row, meta) {
                        if(row.channel.companyRegisterName==null){
                            return row.channel.contact.name;
                        }else{
                            return row.channel.companyRegisterName;
                        }
                    }
                },
                {
                    "data": "channel.contact.telephone",
                    "defaultContent": '--',
                    "bSortable": false
                },
                {
                    "bSortable": false,
                    "defaultContent": '--',
                    "render": function (data, type, row, meta) {
                        var typeInsurance = row.typeInsurance;
                        if(typeInsurance==0){
                            return "交强险";
                        }else if(typeInsurance==1){
                            return "商业险";
                        }
                    }
                },
                {
                    "data": "insurant",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "orgIdCode",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "plateNum",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "mercialPremium",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "pulsoryPremium",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "vechcleVesselTax",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "allPremium",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "dateIssuance",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "datePolicy",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "channelRebate",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "mustRebateAmt",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "payDate",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "mustPremium",
                    "sClass": "text-right",
                    "defaultContent": '--',
                    "bSortable":false
                },
                {
                    "data": "insyrerMaturityDate",
                    "defaultContent": '--',
                    "bSortable":false
                }
            ]
        });

    }


    //详情页
    function showOrderInfo(orderId){
        $("#havePay li:eq(0)").removeClass("active");
        $("#default-tab-1").removeClass("active in")
        $("#default-tab-2").removeClass("active in")
        $("#havePay li:eq(1)").removeClass("active");
        $("#havePay li:eq(2)").removeClass("hidden");
        $("#havePay li:eq(2)").addClass("active");
        $("#default-tab-3").addClass("active in")
        $("#iframe").attr("src","/ins/order/orderInfoDetail?tid="+orderId);
    }
    //查询
    function search() {
        table1.ajax.reload();
    }
    function search1() {
        table2.ajax.reload();
    }
    //打开模态框
    function openModels(ordId,capitalId) {
        /*console.log("ordId"+ordId)
         var ordIds = ordId.split(",")[0];
         var capitalId = ordId.split(",")[1];*/
        console.log("ordId"+ordId)
        console.log("capitalId"+capitalId)

        surrender(capitalId,ordId);
    }

    function doSomeThing() {
        var type = $("#typee").val();
        if(type==1){
            exportTables();
        }else if(type==2){
            exportChannelTable();
        }else if(type==4){
            $('#modalSurrender').modal('hide');
            location = location;
        }else{
            table1.ajax.reload();
            table2.ajax.reload();
            location = location;
        }
        $('#modal-dialog').modal('hide')
    }
    function closeModels() {
        $('#modalSurrender').modal('hide');
        location = location;
    }
    function closeModelss() {
        $('#modal-dialog').modal('hide');
        location = location;
    }
    //下载
    function exportTables() {
        var insyrerId = $('#insyrerId :selected').val()==0?null:$('#insyrerId :selected').val();
        var ordNum = $('#ordNum').val();
        var plateNum = $('#plateNum').val();
        var channelId = $('#channelId').val();
        var insureStartDate = $('#insureStartDate').val();
        var insureEndDate = $('#insureEndDate').val();
        window.location.href="/ins/order/download?insyrerId="+insyrerId+"&ordNum="+ordNum
            +"&channelId="+channelId+"&insureStartDate="+insureStartDate+"&insureEndDate="+insureEndDate
            +"&plateNum="+plateNum;
        //window.location.href = "/ins/order/download";

    }

    function exportChannelTable() {
        var insyrerId = $('#insyrerId1 :selected').val()==0?null:$('#insyrerId1 :selected').val();
        var ordNum = $('#ordNum1').val();
        var plateNum = $('#plateNum1').val();
        var channelId = $('#channelId').val();
        var insureStartDate = $('#insureStartDate1').val();
        var insureEndDate = $('#insureEndDate1').val();
        window.location.href="/ins/order/downloadChannel?insyrerId="+insyrerId+"&ordNum="+ordNum
            +"&channelId="+channelId+"&insureStartDate="+insureStartDate+"&insureEndDate="+insureEndDate
            +"&plateNum="+plateNum;
        //window.location.href = "/ins/order/download";

    }

    //应收订单退保
    function surrender(capitalId, ordId) {
        var formData = new FormData();
        formData.append("capitalId", capitalId);
        formData.append("ordId", ordId);
        $.ajax({
            url: "/receivable/checkSurrenderData",
            type: "POST",
            data: formData,
            //必须false才会自动加上正确的Content-Type
            contentType: false,
            //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
            processData: false,
            success: function (data) {
                if (data.success == true) {
                    var channelFlag = data.result.channelFlag;
                    var channelStatus = data.result.channelStatus;
                    var insureStartDate = data.result.insureStartDate;
                    console.log("insureStartDate"+insureStartDate)
                    if (channelStatus == 4) {
                        $("#me").html("请先完成该渠道应收保费的结算审核");
                        openModel(3);
                        return false;
                    } else {
                        if (channelFlag == 1) {
                            $('#mustPremium').removeClass('hidden');
                            $('#inputMustPremium').attr('type','text');
                            $('#mustPremium').val('');
                        }
                        $('#surrenderTid').val(capitalId);
                        $('#orderTid').val(ordId);
                        $('#channelFlag').val(channelFlag);
                        $('#inputInsuranceDate').html(insureStartDate);
                        $('#inputSurrenderDate').val(new Date().Format("yyyy-MM-dd"));
                        $('#modalSurrender').modal({backdrop: 'static', keyboard: false});
                    }
                } else {
                    $("#me").html(data.msg);
                    openModel(3);
                    return;
                }
            },
            error: function () {
                $("#me").html(data.msg);
                openModel(3);
            }
        });
    }

    function orderSurrender() {
        console.log(1111111)

        var status = $('#myForm').submit().parsley();
        console.log(status.isValid())
        if(status.isValid()){

            $.ajax({
                url: "/receivable/orderSurrender",
                type: "POST",
                async:true,
                data: $('#myForm').serialize(),
                //必须false才会自动加上正确的Content-Type
                //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
                success: function (data) {
                    if (data.success == true) {
                        $('#modalSurrender').modal('hide');
                        $("#me").html(data.msg);
                        openModel(3);
                    } else {
                        $("#me").html(data.msg);
                        openModel(3);
                        return;
                    }
                }
            });
        }
    }
    Date.prototype.Format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

    function openModel(type) {
        $("#typee").val(type);
        if (type==1){
            $("#me").html("确认下载当前列表信息");
        }else if(type==2){
            $("#me").html("确认下载当前列表信息");

        }else if(type==4){

        }else{
            $('#modalSurrender').modal('hide')
        }
        $('#modal-dialog').modal({backdrop: 'static', keyboard: false});
    }
    //关闭模态框
    function closeModel() {
        /*$('#modal-dialog').modal('hide');
         location=location;*/
        $("#me").html("当前填写内容未提交，确认取消？");
        openModel(4);
    }
    //改变下载路径
    function changeUrl(type) {
        $("#havePay li:eq(2)").addClass("hidden");
        $("[name='insyrerId']").val("");
        $("[name='ordNum']").val("");
        $("[name='plateNum']").val("");
        $("[name='channel']").val("");
        $("[name='insureStartDate']").val("");
        $("[name='insureEndDate']").val("");
        $("#channelId").val("");
        if(type==2){
            $("#down1").parent().removeClass("hidden");
            $("#down").parent().addClass("hidden");
        }else{
            $("#down").parent().removeClass("hidden");
            $("#down1").parent().addClass("hidden");
        }
    }
    //获取所有渠道名称
    function getAllChannel() {
        var name = $("#channel").val();
        $.ajax({
            url:"/channel/findAllChannelName/"+name,
            data:{},
            type:"post",
            success:function (data) {
                alert(data);
                console.log("data--------"+data);
            },
            dataType:"json"
        })

    }
</script>
</body>
</html>
